﻿//根据键获取session中的值
function MyJsGetSession(name) {
    var result = "";
    $.ajax({
        url: "/account/AjaxGetSession",
        type: "get",
        cache: false,
        data: { name: name },
        async: false,
        dataType: "json",
        success: function (data) {
            result = data.s;
        }
    });
    return result;
}

//给session赋值
function MyJsSetSession(name, value) {
    $.ajax({
        url: "/account/AjaxSetSession",
        type: "get",
        cache: false,
        data: { name: name, value: value },
        async: false,
        dataType: "json",
        success: function (data) {
        }
    });
}

//取当前url上的参数的值
function getUrlPara(paraName) {
    var url = location.href;
    var str = "(?:\\?|&){1}" + paraName + "=([^&]*)"
    var re = new RegExp(str, "gi");
    re.exec(url);
    return RegExp.$1;
}

//取指定url上的参数的值
function getTheUrlPara(url, paraName) {
    var str = "(?:\\?|&){1}" + paraName + "=([^&]*)"
    var re = new RegExp(str, "gi");
    re.exec(url);
    return RegExp.$1;
}

//把日期转换为2009-06-12 17:18:05格式
function myDateToStr(datetime) {
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1; //js从0开始取 
    var date = datetime.getDate();
    var hour = datetime.getHours();
    var minutes = datetime.getMinutes();
    var second = datetime.getSeconds();

    if (month < 10) {
        month = "0" + month;
    }
    if (date < 10) {
        date = "0" + date;
    }
    if (hour < 10) {
        hour = "0" + hour;
    }
    if (minutes < 10) {
        minutes = "0" + minutes;
    }
    if (second < 10) {
        second = "0" + second;
    }

    var time = year + "-" + month + "-" + date + " " + hour + ":" + minutes + ":" + second; //2009-06-12 17:18:05
    return time;
}

//关闭当前窗口并且不会有提示信息
function closeWindow() {
    window.opener = null;
    window.open('', '_self');
    window.close();
}